using UnityEngine;
using ZFramework.Runtime;
using ZFramework.Runtime.Download;
using ZFramework.Runtime.WebRequest;

namespace ZGame
{
    public class Begin : MonoBehaviour
    {
        public EResPlayMode PlayMode;

        public static EResPlayMode StaticPlayMode;
        // Start is called before the first frame update
        void Start()
        {
            StaticPlayMode = PlayMode;
            DontDestroyOnLoad(gameObject);
            _InitGameEntry();
            _BeginGame();
        }

        void _InitGameEntry()
        {
            AOTGameEntry.baseMgr = FrameworkManagerManager.GetManager<BaseMgr>();
            AOTGameEntry.eventMgr = FrameworkManagerManager.GetManager<EventManager>();
            AOTGameEntry.webRequestManager = FrameworkManagerManager.GetManager<WebRequestManager>();
            AOTGameEntry.downloadManager = FrameworkManagerManager.GetManager<DownloadManager>();
            AOTGameEntry.fsmManager = FrameworkManagerManager.GetManager<FsmManager>();
            AOTGameEntry.procedureManager = FrameworkManagerManager.GetManager<ProcedureManager>();
            AOTGameEntry.resourceManager = FrameworkManagerManager.GetManager<YooResourceMgr>();
            
            //基础管理器
            // var baseMgr = FrameworkManagerManager.CreateManager<BaseMgr>();
            // baseMgr.SetVersionHelper<DefaultVersionHelper>();
            // baseMgr.SetLogHelper<DefaultLogHelper>();
            // baseMgr.SetZipHelper<DefaultZipHelper>();
            // baseMgr.SetJsonHelper<DefaultJsonHelper>();
            // AOTGameEntry.baseMgr = baseMgr;
            //
            // //应用池
            // var goReferencePoolComponent = new GameObject("ReferencePoolComponent");
            // DontDestroyOnLoad(goReferencePoolComponent);
            // var referencePoolComponent = goReferencePoolComponent.AddComponent<ReferencePoolComponent>();
            // //如果是对外版本，就不检查
            // referencePoolComponent.EnableStrictCheck = true;
            //
            // //事件管理器
            // AOTGameEntry.eventMgr = FrameworkManagerManager.CreateManager<EventMgr>();
            //
            // //web request管理器
            // var webRequestMgr = FrameworkManagerManager.CreateManager<WebRequestManager>();
            // webRequestMgr.SetEventMgr(AOTGameEntry.eventMgr);
            // webRequestMgr.SetWebRequestAgentHelperInfo<UnityWebRequestAgentHelper>(10);
            // AOTGameEntry.webRequestManager = webRequestMgr;
            //
            // //下载管理器
            // var downloadMgr = FrameworkManagerManager.CreateManager<DownloadManager>();
            // downloadMgr.SetEventMgr(AOTGameEntry.eventMgr);
            // downloadMgr.SetDownLoadAgentHelperInfo<UnityWebRequestDownloadAgentHelper>(10);
            // AOTGameEntry.downloadManager = downloadMgr;
            //
            // //有限状态机管理器
            // AOTGameEntry.fsmManager = FrameworkManagerManager.CreateManager<FsmManager>();
            //
            // var procedureManager = FrameworkManagerManager.CreateManager<ProcedureManager>();
            // AOTGameEntry.procedureManager = procedureManager;
            //
            // FrameworkManagerManager.Init();
        }

        private void Update()
        {
            FrameworkManagerManager.OnUpdate(Time.deltaTime, Time.unscaledDeltaTime);
        }

        void _BeginGame()
        {
            // GameEntry.gameWorldMgr.CreateGameWorld<GameWorldTest>();
            // GameEntry.gameWorldMgr.CreateGameWorld<GameWorldInitResource>();
            // GameEntry.gameWorldMgr.CreateGameWorld<GameWorldPreLoad>();
            // GameEntry.gameWorldMgr.CreateGameWorld<GameWorldLogin>();
            // //GameEntry.gameWorldMgr.CreateGameWorld<GameWorldChangeScene>();
            // //GameEntry.gameWorldMgr.NextSceneId = 1;
            // GameEntry.gameWorldMgr.StartGameWorld<GameWorldInitResource>();
        }
    }
}
